package pe.com.tma.impl;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder;

import pe.com.tma.dao.AuthenticationDAO;
import pe.com.tma.model.Usuario;

//@Service("authenticationService")
public class AuthenticationServiceImpl implements AuthenticationDAO {


	@Resource(name = "authenticationManager")
	private AuthenticationManager authenticationManager; // specific for Spring Security

	@Override
	public boolean login(String username, String password) {
		try {
			Authentication authenticate = authenticationManager
					.authenticate(new UsernamePasswordAuthenticationToken(
							username, password));
			if (authenticate.isAuthenticated()) {
				SecurityContextHolder.getContext().setAuthentication(
						authenticate);				
				return true;
			}
		} catch (AuthenticationException e) {			
		}
		return false;
	}

	@Override
	public void logout() {
		SecurityContextHolder.getContext().setAuthentication(null);
		//currentUser.unauthenticate();
	}

	@Override
	public List<Usuario> buscarUsuarioPorCodigo(String username) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List buscarPerfilesDeUsuarioPorCodigo(String username) {
		// TODO Auto-generated method stub
		return null;
	}

	
}
